﻿using System;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.BarterSystem.Barterables
{
	// Token: 0x02000414 RID: 1044
	public class FiefBarterable : Barterable
	{
		// Token: 0x17000D21 RID: 3361
		// (get) Token: 0x06003F7E RID: 16254 RVA: 0x00139CE5 File Offset: 0x00137EE5
		public override string StringID
		{
			get
			{
				return "fief_barterable";
			}
		}

		// Token: 0x17000D22 RID: 3362
		// (get) Token: 0x06003F7F RID: 16255 RVA: 0x00139CEC File Offset: 0x00137EEC
		public Settlement TargetSettlement
		{
			get
			{
				return this._settlement;
			}
		}

		// Token: 0x17000D23 RID: 3363
		// (get) Token: 0x06003F80 RID: 16256 RVA: 0x00139CF4 File Offset: 0x00137EF4
		public override TextObject Name
		{
			get
			{
				return this._settlement.Name;
			}
		}

		// Token: 0x06003F81 RID: 16257 RVA: 0x00139D01 File Offset: 0x00137F01
		public FiefBarterable(Settlement settlement, Hero owner, Hero heroOfferedTo) : base(owner, null)
		{
			this._settlement = settlement;
			this._heroOfferedTo = heroOfferedTo;
		}

		// Token: 0x06003F82 RID: 16258 RVA: 0x00139D1C File Offset: 0x00137F1C
		public override int GetUnitValueForFaction(IFaction faction)
		{
			float num = 1f;
			if (faction == this._heroOfferedTo.Clan)
			{
				num = 1f;
			}
			else if (faction == base.OriginalOwner.Clan)
			{
				num = -1f;
			}
			else if (faction.MapFaction == this._heroOfferedTo.MapFaction)
			{
				num = 1f;
			}
			else if (faction.MapFaction == base.OriginalOwner.MapFaction)
			{
				num = -1f;
			}
			float num2 = Campaign.Current.Models.SettlementValueModel.CalculateSettlementValueForFaction(this._settlement, faction);
			return (int)(num * num2);
		}

		// Token: 0x06003F83 RID: 16259 RVA: 0x00139DAF File Offset: 0x00137FAF
		public override ImageIdentifier GetVisualIdentifier()
		{
			return null;
		}

		// Token: 0x06003F84 RID: 16260 RVA: 0x00139DB2 File Offset: 0x00137FB2
		public override string GetEncyclopediaLink()
		{
			return this.TargetSettlement.EncyclopediaLink;
		}

		// Token: 0x06003F85 RID: 16261 RVA: 0x00139DBF File Offset: 0x00137FBF
		public override void Apply()
		{
			ChangeOwnerOfSettlementAction.ApplyByBarter(this._heroOfferedTo, this._settlement);
		}

		// Token: 0x06003F86 RID: 16262 RVA: 0x00139DD2 File Offset: 0x00137FD2
		internal static void AutoGeneratedStaticCollectObjectsFiefBarterable(object o, List<object> collectedObjects)
		{
			((FiefBarterable)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x06003F87 RID: 16263 RVA: 0x00139DE0 File Offset: 0x00137FE0
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			collectedObjects.Add(this._settlement);
			collectedObjects.Add(this._heroOfferedTo);
		}

		// Token: 0x06003F88 RID: 16264 RVA: 0x00139E01 File Offset: 0x00138001
		internal static object AutoGeneratedGetMemberValue_settlement(object o)
		{
			return ((FiefBarterable)o)._settlement;
		}

		// Token: 0x06003F89 RID: 16265 RVA: 0x00139E0E File Offset: 0x0013800E
		internal static object AutoGeneratedGetMemberValue_heroOfferedTo(object o)
		{
			return ((FiefBarterable)o)._heroOfferedTo;
		}

		// Token: 0x04001292 RID: 4754
		[SaveableField(100)]
		private readonly Settlement _settlement;

		// Token: 0x04001293 RID: 4755
		[SaveableField(101)]
		private readonly Hero _heroOfferedTo;
	}
}
